package com.fzd.code.excel;

import java.util.HashMap;
import java.util.Map;

public class Record {
  private Map<String, Object> queryFields = new HashMap<String, Object>();
  private int fieldCnt = 0;
  private Map<String, String> fieldIndexMap = new HashMap<String, String>();

  public int getFieldCnt() {
    return fieldCnt;
  }

  public void addField(String fieldName, Object fieldValue) {
    queryFields.put(fieldName, fieldValue);
    fieldIndexMap.put(String.valueOf(fieldCnt++), fieldName);
  }
  
  public void updateField(String fieldName, Object fieldValue) {
    queryFields.put(fieldName, fieldValue);
    if (!fieldIndexMap.containsValue(fieldName)) {
      fieldIndexMap.put(String.valueOf(fieldCnt++), fieldName);
    }
  }
  
  public Object getValueByName(String fieldName) {
    return queryFields.get(fieldName);
  }
  
  public Object getValueByIndex(int fieldIndex) {
    String fieldName = (String)fieldIndexMap.get(String.valueOf(fieldIndex));
    if (fieldName != null) {
      return queryFields.get(fieldName);
    }
    return null;
  }
  
  public String getNameByIndex(int fieldIndex) {
    String fieldName = (String)fieldIndexMap.get(String.valueOf(fieldIndex));
    return fieldName;
  }

  public boolean nameMatch(String fieldName) {
	  return queryFields.containsKey(fieldName);
  }

  public boolean nameTrimMatch(String fieldName) {
	  for(String k:queryFields.keySet()){
		  if (fieldName.equals(k.trim())) {
			return true;
		  }
	  }
	  return false;
  }
}
